package com.ruanjian.api.utils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回对象封装
 * @author shkstart
 * @create 2022-11-08 16:28
 */
public class AjaxResult {

    /** 状态码：200成功，0失败 */
    private int code;
    /** 返回提示信息 */
    private String msg;
    /** 返回数据 */
    private Map<String,Object> data = new HashMap<>();

    public AjaxResult(){

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    /**
     * 处理成功操作
     * @return
     */
    public static AjaxResult success(){
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMsg("处理成功");
        return result;
    }

    /**
     * 处理失败操作
     * @return
     */
    public static AjaxResult fail(){
        AjaxResult result = new AjaxResult();
        result.setCode(0);
        result.setMsg("处理失败");
        return result;
    }

    /**
     * 链式操作
     * @param key 键
     * @param value 值
     * @return
     */
    public AjaxResult add(String key, Object value){
        this.getData().put(key, value);
        return this;
    }

}
